home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dialog / checklist1.c < prev    next >
C/C++ Source or Header  |  1996-08-01  |  1KB  |  44 lines

  1. #include "diadef.h"
  2. #include "dialog.h"
  3.  
  4. /*
  5.  * Display a dialog box with a list of options that can be turned on or off
  6.  */
  7. int dialog_checklist_p(
  8.     const char *title,
  9.     const char *prompt,
  10.     const char *helpfile,
  11.     int list_height,
  12.     int item_no,
  13.     char **items)
  14.  
  15. {
  16.     int ret = -1;
  17.     /* Allocate space for storing item on/off status */
  18.     char *status = (char*)malloc(item_no);
  19.     char **tmp_items = (char**)malloc(item_no*2*sizeof(char*));
  20.     if (status == NULL || tmp_items == NULL) {
  21.         endwin();
  22.         fprintf(stderr, "\nCan't allocate memory in dialog_checklist().\n");
  23.         exit(-1);
  24.     }else{
  25.         /* Initializes status */
  26.         int i;
  27.         for (i = 0; i < item_no; i++){
  28.             status[i] = !strcasecmp(items[i*3 + 2], "on");
  29.             tmp_items[i*2] = items[i*3];
  30.             tmp_items[i*2+1] = items[i*3+1];
  31.         }
  32.         ret = dialog_checklist (title,prompt,helpfile,list_height,item_no,items,status);
  33.         if (ret == 0){
  34.             for (i = 0; i < item_no; i++){
  35.                 if (status[i]) fprintf(stderr, "\"%s\" ", items[i*3]);
  36.             }
  37.         }
  38.         free (status);
  39.         free (tmp_items);
  40.     }
  41.     return ret;
  42. }
  43.  
  44.